# COPYRIGHT_CHUNFENG
include config.mk
include libs.mk
OS ?= LINUX32
CC ?= gcc
CFLAGS += -Wall -Wno-unused-label -Wno-unused-function
LDFLAGS += -Wl,--as-needed
ifeq ($(OS),WIN32)
CFLAGS += -D_WIN32_
else
CFLAGS += 
endif
ifeq ($(CONFIG_DEBUG),y)
CFLAGS += -g
LDFLAGS += -g
else
CFLAGS += -s
LDFLAGS += -s -O2
endif
VER = $(shell cat VERSION)

#####################################################
ifeq ($(OS), WIN32)
TARGET = libchunfeng.dll
else
TARGET = libchunfeng.so
endif
CFLAGS +=  -I./include -fPIC
LDFLAGS += -Wl,-soname -Wl,$(TARGET) -shared -lm -lcrypt

OBJS = cf_string.o cf_buffer.o cf_list.o cf_list_file.o cf_key_value_file.o cf_log.o cf_common.o
OBJS += cf_fstab_file.o
OBJS += cf_queue.o
OBJS += cf_std.o
ifeq ($(OS), WIN32)
else
OBJS += cf_timer.o
OBJS += cf_sigfd.o
OBJS += cf_network.o
OBJS += cf_fdevent.o
OBJS += cf_shadow_file.o
OBJS += cf_passwd_file.o
endif
OBJS += cf_www.o
ifeq ($(ENABLE_FCGI), yes)
OBJS += cf_fcgi.o
endif
ifeq ($(ENABLE_BLKID), yes)
OBJS += cf_blkid.o
endif
OBJS += cf_session.o
OBJS += cf_cgi.o
OBJS += cJSON.o
OBJS += cf_json.o
#OBJS += cf_hash_table.o

ifeq ($(CONFIG_USE_LCF_LOG), yes)
CFLAGS += -D_USE_LCF_LOG_
endif
###################################

all:$(TARGET)

$(TARGET):$(TARGET).$(VER)
ifeq ($(OS),WIN32)
	mv $^ $@
else
	ln -sf $^ $@
endif


$(TARGET).$(VER):$(OBJS)
	$(CC) $(LDFLAGS) -o$@ $^

install:
	mkdir -p $(INSTALL_PATH)/usr/lib
	cp -af ${TARGET} ${TARGET}.${VER} $(INSTALL_PATH)/usr/lib

uninstall:
	rm -rf $(INSTALL_PATH)/usr/lib/${TARGET} $(INSTALL_PATH)/usr/lib/${TARGET}.$(VER)

clean:
	rm -rf test $(TARGET)  $(TARGET).${VER} *.o

.PHONY : all clean install uninstall

